<template>
  <!-- 编辑 商品修改 -->
  <div id="ShopEdit" class="ShopEdit">
    <header>商品管理--修改商品</header>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="商品名称">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="商品描述">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="所属分类">
        <el-select v-model="form.region" placeholder="请选择一级品类">
          <el-option label="区域一" value></el-option>
          <el-option label="区域二" value></el-option>
        </el-select>
        <el-select v-model="form.region" placeholder="请选择二级品类">
          <el-option label="区域一" value></el-option>
          <el-option label="区域二" value></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="商品价格">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="商品库存">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="商品图片">
        <el-upload
          class="upload-demo"
          name="upload_file"
          list-type="picture-card"
          action="/api/product/upload.do"
          :on-preview="handlePreview"
          :on-remove="handleRemove"
          :before-remove="beforeRemove"
          v-model="list.subImages"
          multiple
          :limit="3"
          :on-success="handleSuccess"
          :on-exceed="handleExceed"
          :file-list="fileList"
        >
          <el-button size="small" type="primary">点击上传</el-button>
          <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
        </el-upload>
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt />
        </el-dialog>
      </el-form-item>

      <el-form-item label="商品详情">
        <el-input type="textarea" v-model="form.desc"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  props: {},
  name: "ShopEdit",
  data() {
    return {
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      list: {
        subImages: "",
      },
      fileList: [
        {
          name: "food.jpeg",
          url:
            "https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100",
        },
        {
          name: "food2.jpeg",
          url:
            "https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100",
        },
      ],
      dialogImageUrl: "",
      dialogVisible: false,
    };
  },
  created() {},
  computed: {},
  components: {},
  methods: {
    // 方法集合
    onSubmit() {
      console.log("submit!");
    },

    handleSuccess(response, file, fileList) {
      console.log(response.data);
      this.list.subImages = response.data.uri;
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file, fileList) {
      console.log(file, this.fileList);
      //    this.list.subImages = response.data.uri;
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
          files.length + fileList.length
        } 个文件`
      );
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
  },
  mounted() {
    // 页面进入时加载内容
    // ShopEditpic.then((data)=>{
    //     console.log(data)
    // })
  },
  watch: {
    // 监测变化
  },
};
</script>
<style scoped lang="scss">
header {
  width: 100%;
  height: 50px;
  line-height: 50px;
  font-size: 26px;
  text-indent: 20px;
}
.el-form {
  .el-input {
    width: 60%;
    .el-input__inner {
      width: 50%;
      background: #000;
    }
  }
}
</style>